<?php
// 本类由系统自动生成，仅供测试用途
class LoginAction extends BaseAction {
	public function _initialize() {
		parent::_initialize();
              
    }
    public function index(){
	$this->display();
    }
	public function doLogin(){//登陆
	    
		$username = $_POST['username'];
		$password = $_POST['password'];
		$code= $_POST['code'];
		
		
		if(md5($code)!=$_SESSION['code']){
			$this->error('验证码不正确！');
		}
		
		$user = M('User');
		$where['username'] = $username;
		$where['password'] = $password;
		$arr = $user->field('id')->where($where)->find();
		
		if($arr){
			$_SESSION['username'] = $username;
			$_SESSION['id']       = $arr['id'];
			$this->redirect('Index/index');
		}else{
			$this->error('用户不存在');
		}
	}
	
	public function doLogout(){//退出登陆登陆
		$_SESSION = array();
		if(isset($_COOKIE[session_name()])){
			setcookie(session_name(),'',time()-1,'/');			
		}
		session_destroy();
		$this->redirect('Index/index');
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
    



}